﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace Utility.Math
{
	public struct Circle
	{
		public static readonly Circle UnitCircle = new Circle (Vector2.zero, 1);

		public float radius;
		public Vector2 center;

		public Circle (Vector2 center, float radius)
		{
			if (radius <= 0)
			{
				throw new ArgumentException ("radius cannot <=0");
			}
			this.radius = radius;
			this.center = center;
		}

		public Circle (float radius) : this (Vector2.zero, radius) { }

		public float Diameter { get { return radius * 2; } }
		public float Area { get { return Mathf.PI * radius * radius; } }
		public float Perimeter { get { return Mathf.PI * radius * 2; } }

		public bool IsOverlap (Circle other)
		{
			float radiusSum = this.radius + other.radius;
			return (this.center - other.center).sqrMagnitude < radiusSum * radiusSum;
		}

		public bool IsIntersect (Circle other)
		{
			float radiusSum = this.radius + other.radius;
			return (this.center - other.center).sqrMagnitude == radiusSum * radiusSum;
		}

		public bool IsNonContact (Circle other)
		{
			float radiusSum = this.radius + other.radius;
			return (this.center - other.center).sqrMagnitude > radiusSum * radiusSum;
		}
	}
}